//
//  CommodityDetailInfo.m
//  HWZB
//
//  Created by 许成雄 on 2017/5/2.
//  Copyright © 2017年 wonders. All rights reserved.
//

#import "CommodityDetailInfo.h"
#import "PackageInfo.h"

@implementation CommodityDetailInfo

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"commodityId" : @"id",
             @"imageUrl" : @"image",
             @"imageUrl2" : @"image2",
             @"imageUrl3" : @"image3",
             @"imageUrl4" : @"image4",
             @"imageUrl5" : @"image5",
             @"isIndex" : @"isIndex",
             @"order" : @"order",
             @"price" : @"price",
             @"productDetail" : @"productDetail",
             @"productName" : @"productName",
             @"typeId" : @"productTypeId",
             @"typeName" : @"productTypeName",
             @"refreshTime" : @"refreshTime",
             @"state" : @"state",
             @"packageList" : @"models"
             };
}

+ (NSValueTransformer *)commodityIdJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)priceJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)typeIdJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)stateJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)packageListJSONTransformer {
    return [MTLValueTransformer reversibleTransformerWithBlock:^id(id value) {
        NSArray *packageArray = [MTLJSONAdapter modelsOfClass:[PackageInfo class] fromJSONArray:value error:nil];
        return packageArray;
    }];
}


@end
